<?php
// +-------------------------------------------------------------------------------
// | DingZone [ A Rapid Development Framework For Dingtalk ]
// +-------------------------------------------------------------------------------
// | 钉钉消息基础类 v1.0
// |
// | Copyright (c) 2014-2018 http://www.heimalanshi.com All rights reserved.
// | Author : Jie
// | Date : 2018-08-09
// +-------------------------------------------------------------------------------

namespace ding\msg\chat;

/**
 * 回话消息
 *
 * @package ding\msg\chat
 */
abstract class ChatMsg {
    protected $msgtype;

    /**
     * 构造函数
     * @param $msgtype
     */
    public function __construct($msgtype) {
        $this->msgtype = $msgtype;
    }

    /**
     * 转换为可发送的消息格式
     *
     * @return array
     */
    public function toMsg() {
        return [
            'msgtype' => $this->msgtype,
            $this->msgtype => $this->getMsgContent()
        ];
    }

    /**
     * 获取消息体
     *
     * @return mixed
     */
    abstract public function getMsgContent();

    /**
     * @return string
     */
    public function getMsgtype() {
        return $this->msgtype;
    }
}